// pages/result/result.js
const api = require('../../util')
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        statusBarHeight: app.globalData.statusBarHeight,

        num: 1,
        distance: 0, // 箭头位置
        color: '', // 得分颜色
        options: {},
        details: [],
        results: [],
        display_button: '',
        list: []
    },
    // 再次测试
    toevaluation() {
        var id = ''
        wx.redirectTo({
            url: '/pages/evaluation/evaluation?category_id='+this.data.options.category_id,
        })
    },
    // 帮帮圈
    togangcircle() {
        wx.switchTab({
            url: '/pages/gangcircle/gangcircle',
        })
    },
    // 在线复诊
    tofollowup() {
        wx.redirectTo({
            url: '/pages/followup/followup',
        })
    },
    // 健康报告
    tohealthreport() {
        if (getCurrentPages()[0].route =='pages/home/home') {
            wx.reLaunch({
                url: '/pages/healthreport/healthreport',
            })  
        } else {
            wx.navigateBack({
                delta: 1
            })
        }
    },
    before() {
        wx.navigateBack({
            delta: 1
        })
    },
    // 获取测评结果
    getAssessmentResults() {
        var arr=this.data.options.data,that=this
        api.http('/Subject/getAssessmentResults', 'POST', true, {
            data: arr,
            category_id: this.data.options.category_id
        }, function (res) {
            if(res.code == 200) {
                for (let i = 0; i < res.data.details.length; i++) {
                    for (let j = 0; j < res.data.details[i].subject.length; j++) {
                        for (let z = 0; z < res.data.details[i].subject[j].options.length; z++) {
                            if (res.data.details[i].subject[j].options[z].option.length>4) {
                                res.data.details[i].subject[j].type = true
                            }
                        }
                    }
                }
                that.setData({
                    details: res.data.details,
                    display_button: res.data.display_button,
                    results: res.data.results
                })
            } else {
                wx.showToast({
                    title: res.msg,
                    icon: 'none',
                    duration: 1000
                })
            }
        })
    },
    // 获取详情
    assessmentDetails() {
        var that=this
        api.http('/Subject/assessmentDetails', 'POST', true, {
            evaluation_result_id: this.data.options.evaluation_result_id
        }, function (res) {
            if(res.code == 200) {
                for (let i = 0; i < res.data.details.length; i++) {
                    for (let j = 0; j < res.data.details[i].subject.length; j++) {
                        for (let z = 0; z < res.data.details[i].subject[j].options.length; z++) {
                            if (res.data.details[i].subject[j].options[z].option.length>4) {
                                res.data.details[i].subject[j].type = true
                            }
                        }
                    }
                }
                that.setData({
                    details: res.data.details,
                    display_button: res.data.display_button,
                    results: res.data.results
                })
            }
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.setData({
            options: options
        }, () => {
            if(typeof(options.evaluation_result_id)=='undefined') {
                // 获取详情
                this.getAssessmentResults()
            } else {
                // 获取测评结果 *答题页面进入
                this.assessmentDetails()
            }
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    // onShareAppMessage() {

    // }
})